package com.otherTest.sort;


import org.junit.Test;

/**
 * @Description: 选择排序，与冒泡排序恰恰相反，前值与每个后值进行比较，小的放到前面
 * @author: conceit
 * @Date: 2018/11/5  10:46
 */
public class SelectSort {


    @Test
    public void test1() {
        int[] sort = {6, 1, 11, 7, 9, 3, 4, 5, 10, 8, 2};
        System.out.println("sort.length-->" + sort.length);
        for (int i = 0; i < sort.length; i++) {

            for (int j = i + 1; j < sort.length; j++) {
                if (sort[i] > sort[j]) {
                    int temp = sort[j];
                    sort[j] = sort[i];
                    sort[i] = temp;
                }
            }


        }
        System.out.println("遍历完成！");
        for (int s : sort) {
            System.out.println(s);
        }


    }


    @Test
    public void test2() {
        int[] sort = {6, 1, 11, 7, 9, 3, 4, 5, 10, 8, 2};
        System.out.println("sort.length-->" + sort.length);

        for (int i = 0; i < sort.length; i++) {
            System.out.print(i + "-");
            System.out.println(sort[i]);
            for (int j = i + 1; j < sort.length; j++) {
                if (sort[i] > sort[j]) {
                    int temp = sort[j];
                    sort[j] = sort[i];
                    sort[i] = temp;

                }
            }
        }
        System.out.println("遍历完成！");
        for (int s : sort) {
            System.out.println(s);
        }
    }


}
